<?php
include("include/config.inc.php");

$id=$_REQUEST["id"];

if(!CheckId($id))
{
	PhpBox("参数错误");
	GotoPage("h");
	exit();
}
$sql="SELECT * FROM ".tableprefix."goods where goods_id='$id'";
$result=$db->query($sql);
$row=$db->fetch_array($result);
$goods_commonid=$row["goods_commonid"];
$store_id=$row["store_id"];
$code=$row["code"];

$sql="SELECT * FROM ".tableprefix."store where store_id='$store_id'";
$result=$db->query($sql);
$store=$db->fetch_array($result);
$grade_id=$store["grade_id"];
if($grade_id=='2'){
$temp_store_credit='诚信商户';
}elseif($grade_id=='3'){
$temp_store_credit='特约商户';
}else{
$temp_store_credit='普通商户';
}

$sql = "select count(*) as c from ".tableprefix."collection where classify='goods' and goods_id='$id'";
$c=$db->fetch_array($db->query($sql));
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>剧目详情 - 订戏会</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=9,Chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" co  ntent="black" />
<!-- css -->
<link rel="stylesheet" type="text/css" href="css/frameCss/swiper.css"/>
<link rel="stylesheet" type="text/css" href="css/public.css">
<link rel="stylesheet" type="text/css" href="css/index.css">
<script type="text/javascript" src="js/clientwidth.js"></script>
<script type="text/javascript" src="js/scroll.js"></script>
<style type="text/css">
.scroll{margin:0px auto;width:100%;height:250px;overflow:hidden;position:relative;}
.mod_01{float:left;width:640px;}
.mod_01 img{display:block;width:100%;height:250px;}
.dotModule_new{padding:0 5px;height:15px;line-height:6px;-webkit-border-radius:11px;background:rgba(45,45,45,0.5);position:absolute;bottom:5px;right:10px;z-index:1;}
#slide_01_dot{text-align:center;margin:3px 0 0 0;}
#slide_01_dot span{display:inline-block;margin:0 3px;width:5px;height:5px;vertical-align:middle;background:#f7f7f7;-webkit-border-radius:5px;}
#slide_01_dot .selected{background:#66ff33;}
</style>
<script src="js/jquery-1.11.1.min.js"></script>
<script>
/*<![CDATA[*/
function dialogAnimate(dialog , fullscreen) {
	
	var _this = this;
	var fixPosition = 100;
	this.init = function() {
		_this.dialogBodyHeight = $(dialog).outerHeight();
		_this.visibleTop = $(window).outerHeight() - _this.dialogBodyHeight;
		_this.hiddenTop = $(window).outerHeight() + fixPosition;
		$(dialog).css('top' , _this.hiddenTop + 'px');	
	}
	
	this.init();
	
	this.open = function(){
		_this.init();
		$(fullscreen).removeClass('m-hide');
		$(dialog).css('visibility', 'visible');
		$(dialog).animate({'top' : _this.visibleTop + 'px'}, 50);
	}
	
	this.close = function() {
		
		//var hiddenTop = $(window).outerHeight();
		
		$(dialog).animate({'top' : _this.hiddenTop + 'px'}, 50,function() {
			$(dialog).css('visibility' , 'hidden');
			$(fullscreen).addClass('m-hide');
		});
	};
	
	
	this.auto = function(submit, close) {
		$(document).on("click", submit, function(e){
			e.preventDefault();
			_this.open();
		});
		$(document).on("click" ,close,function(e){
			e.preventDefault();
			_this.close();
		});
	};
}

/*]]>*/
</script>
<script type="text/javascript">		
$(function(){
	function goBack(){
		$('.back').on('touchstart',function(){
		window.history.back(-1);
	})
}
goBack();
})	
</script>
<script src="js/jquery.js"></script>
<script type="text/javascript">
			function button1(){
			$("#mcover").css("display","block")    // 分享给好友按钮触动函数
			}
			function button2(){
			$("#mcover").css("display","block")  // 分享给好友圈按钮触动函数
			}
			function weChat(){
			$("#mcover").css("display","none");  // 点击弹出层，弹出层消失
			}
			
			/*$
			(function(){
			   setTimeout(function () {
					$("#mcover").show();}, 6000);   // 6000时毫秒是弹出层
			setTimeout(function () {
					$("#mcover").hide(); }, 8000);    //8000毫秒是隐藏层
			})
			*/
</script>
</head>
<body>
<div id="mcover" onClick="weChat()" style="display:none;"><img src="images/share.png" /></div>
<div class="head-nav">
	<div class="head-left"><div class="back">返回</div></div>
	<div class="head-center">详情</div>
	<div class="head-right"><a href="#" onClick="button1()"><div class="share">分销赚钱</div></a></div>
</div>
<!-- 代码 开始 -->

<div id="container-wrapper">

	<div id="container">
		<!--轮播图-->
		<div class="banner swiper-container">
	        <div class="swiper-wrapper">
<?php
$result = $db->query("select * FROM ".tableprefix."img where flag='T' and imgtype='thumb' and code='$code' ORDER BY id ASC limit 0,10");
while($rs_slide = $db->fetch_array($result))
{
?>
	            <div class="swiper-slide"><a href="<?php echo $rs_slide["imgpath"];?>"><img src="<?php echo $rs_slide["imgpath"];?>" height="320px" width="100%"/></a></div>
<?php
}
?>
	        </div>
	        <div class="swiper-pagination"></div>
	    </div>
	</div>
</div>

<div id="itembox">
	<div class="bigtitle"><?php echo $row["goods_name"];?></div>
	<div class="retime">演出费用：<font color="#FF0000"><?php echo $row["goods_price"];?></font>元</div>
	<div class="retime">预交订金：<font color="#FF0000"><?php echo $row["book_down_payment"];?></font>元</div>
	
</div>

<a href="store/index.php?id=<?php echo $row["store_id"];?>">
<div id="shangjia">    
	<img src="<?php if(GetValueByKey(tableprefix."store","store_id",$row["store_id"],"store_label")==''){echo "images/storenav_01.jpg";}else{echo GetValueByKey(tableprefix."store","store_id",$row["store_id"],"store_label");}?>">
	<h1><?php echo GetValueByKey(tableprefix."store","store_id",$row["store_id"],"store_name");?><span><?php echo $temp_store_credit;?></span></h1>
	<span>卖家好评率<font>100%</font></span>
</div>
</a>

<div id="itemmain">
	<div class="itemtitle">剧目详情</div>
	<div class="itemcontent"><?php echo $row["goods_body"];?></div>
</div>

<div id="itemmain">
	<div class="itemtitle">剧目评价</div>
<?php
$consql.="and geval_goodsid='$id'";
$sql = "select count(*) as count from ".tablepre."evaluate_goods where 1=1 ".$consql;
$rs=$db->fetch_array($db->query($sql));
$count=$rs["count"];

$sql="select * from ".tablepre."evaluate_goods where 1=1 ".$consql." limit 0,20";
$result=$db->query($sql);
if($count>0){
while($rs_pj = $db->fetch_array($result)){
?>
	<div class="itemtab">
		<div class="itemleft"><img src="<?php if(GetValueByKey(tablepre."member","member_id",$rs_pj["geval_frommemberid"],"member_avatar")<>''){echo GetValueByKey(tablepre."member","member_id",$rs_pj["geval_frommemberid"],"member_avatar");}else{echo "images/default_avatar.jpg";}?>"></div>
		<div class="itemright">
			<div class="itemname2"><em><?php echo $rs_pj["geval_frommembername"];?></em>购买<i><?php echo $rs_pj["geval_goodsprice"];?>元</i></div>
			<div class="itemstar"><?php for ($x=1; $x<=$rs_pj["geval_scores"];$x++){echo "★";}?><?php for ($y=1; $y<=5-$rs_pj["geval_scores"];$y++){echo "☆";}?>
			</div>
			<div class="itemtext"><?php echo $rs_pj["geval_content"];?></div>
			<div class="itemtime">评价时间 <?php echo date("Y-m-d",$rs_pj["geval_addtime"]);?></div>
		</div>
	</div>
<?php
}
}else{
echo "<div style='padding:50px 0px;text-align:center;color:#990000;font-size:12px;'>暂无评价<br>
期待您的购买与评论！</div>";
}
?>	
</div>

<div id="bottom" style="margin-bottom:70px;"></div>

<footer id="bar-fixed">
	<a href="api/collection.php?a=goods&storeid=<?php echo $row["store_id"];?>&id=<?php echo $id;?>"><span id="btn-follow"><i style="background-position:0 -24px;"></i>收藏<small><?php echo $c["c"];?></small></span></a>
	<a href="order.php?id=<?php echo $id;?>" class="tab-item2">立即定购</a>
	<a href="#" onClick="button1()"><span data-toggle="modal" data-target="#project-share"><i style="background-position:0 -48px;"></i>分享<small></small></span></a>
</footer>
<!-- 微信转发分享 标题、缩略图、描述问题 START -->
<?php
$appId = 'wxa4cf994a9d00afb8';
$appsecret = '28a4904474f43a2b5b7baf4b907fdbdc';
$timestamp = time();
$jsapi_ticket = make_ticket($appId,$appsecret);
$nonceStr = make_nonceStr();
$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$signature = make_signature($nonceStr,$timestamp,$jsapi_ticket,$url);
function make_nonceStr()
{
	$codeSet = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	for ($i = 0; $i<16; $i++) {
		$codes[$i] = $codeSet[mt_rand(0, strlen($codeSet)-1)];
	}
	$nonceStr = implode($codes);
	return $nonceStr;
}
function make_signature($nonceStr,$timestamp,$jsapi_ticket,$url)
{
	$tmpArr = array(
	'noncestr' => $nonceStr,
	'timestamp' => $timestamp,
	'jsapi_ticket' => $jsapi_ticket,
	'url' => $url
	);
	ksort($tmpArr, SORT_STRING);
	$string1 = http_build_query( $tmpArr );
	$string1 = urldecode( $string1 );
	$signature = sha1( $string1 );
	return $signature;
}
function make_ticket($appId,$appsecret)
{
	// access_token 应该全局存储与更新，以下代码以写入到文件中做示例
	$data = json_decode(file_get_contents("access_token.json"));
	if ($data->expire_time < time()) {
		$TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appId."&secret=".$appsecret;
		$json = file_get_contents($TOKEN_URL);
		$result = json_decode($json,true);
		$access_token = $result['access_token'];
		if ($access_token) {
			$data->expire_time = time() + 7000;
			$data->access_token = $access_token;
			$fp = fopen("access_token.json", "w");
			fwrite($fp, json_encode($data));
			fclose($fp);
		}
	}else{
		$access_token = $data->access_token;
	}
	// jsapi_ticket 应该全局存储与更新，以下代码以写入到文件中做示例
	$data = json_decode(file_get_contents("jsapi_ticket.json"));
	if ($data->expire_time < time()) {
		$ticket_URL="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
		$json = file_get_contents($ticket_URL);
		$result = json_decode($json,true);
		$ticket = $result['ticket'];
		if ($ticket) {
			$data->expire_time = time() + 7000;
			$data->jsapi_ticket = $ticket;
			$fp = fopen("jsapi_ticket.json", "w");
			fwrite($fp, json_encode($data));
			fclose($fp);
		}
	}else{
		$ticket = $data->jsapi_ticket;
	}
	return $ticket;
}
?>
<!--<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>-->
<script src="js/jweixin-1.0.0.js"></script>
<script>
	wx.config({
		//debug: true,
		debug: false,
		appId: '<?php echo $appId;?>',
		timestamp: <?php echo $timestamp;?>,
		nonceStr: '<?php echo $nonceStr;?>',
		signature: '<?php echo $signature;?>',
		jsApiList: [
			'checkJsApi',
			'onMenuShareTimeline',
			'onMenuShareAppMessage'
		  ]
	});
	wx.ready(function () {
		var shareData = {
			title: '<?php echo $row["goods_name"];?>',
			desc: '<?php echo $row["goods_body"];?>',
			link: '<?php echo WEB_PATH;?>mobile/store/share.php?u=<?php echo $ticket;?>&id=<?php echo $row["goods_id"];?>',
			imgUrl: '<?php echo WEB_PATH;?>mobile/images/wycn.jpg'
		};
		wx.onMenuShareAppMessage(shareData);
		wx.onMenuShareTimeline(shareData);
	});
	wx.error(function (res) {
	  alert(res.errMsg);
	});
</script>
<!-- 微信转发分享 标题、缩略图、描述问题 END -->
<!-- <script src="js/itemDetail.js?v=1.0"></script>-->
<script>
if (document.body.clientWidth > 640) {
	$('body').css({
		width: 640,
		margin: '0 auto',
	});
}
</script>
<!-- js -->
<script src="js/frameJS/jquery-2.1.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/clientwidth.js" type="text/javascript"></script>
<script src="js/frameJS/iscroll/build/iscroll.js" type="text/javascript" charset="utf-8"></script>
<script src="js/frameJS/swiper.min.js" type="text/javascript" charset="utf-8"></script>
<script>
	$(function(){
		
		if (document.body.clientWidth > 640) {
			$('body').css({
				width: 640,
				margin: '0 auto',
			});
		}
		
		//引用iScroll并调用
		function loaded(){
			var myScroll = new IScroll('#container-wrapper', {
				scrollbars: true,
				mouseWheel: true,
				interactiveScrollbars: true,
				shrinkScrollbars: 'scale',
				fadeScrollbars: true,
				//click:true防止点击事件或a标签失效
				click:true,
			});
		}
		window.setTimeout(loaded,100);
		
		//头部轮播图
		var swiper = new Swiper('.swiper-container', {
	        pagination: '.swiper-pagination',
	        paginationClickable: true,
	        autoplay:3000
	    });
	})

</script>
</body>
</html>